/**
* @description: 周赛306 t2
* @author hewei
* @date 2022/8/14 10:40
* @version 1.0
*/

public class EdgeScore {

    public int edgeScore(int[] edges) {
        int n = edges.length;
        long[] temp = new long[n];
        boolean[] flag = new boolean[n];
        for (int i = 0; i < edges.length; i++) {
            temp[edges[i]] += i;
            flag[edges[i]] = true;
        }
        int max = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            if ((max == Integer.MAX_VALUE || temp[i] > temp[max]) && flag[i]) max = i;
        }
        return max;
    }
}
